[FE] - PHUONG BUI THANH (Michael - btphuong2017@gmail.com)#291
Open
btphuong2017 wants to merge 4 commits into
Open
[FE] - PHUONG BUI THANH (Michael - btphuong2017@gmail.com)#291btphuong2017 wants to merge 4 commits into
btphuong2017 wants to merge 4 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Solutions — 99Tech Code Challenge #1
Problem 1: Three ways to sum to n
Location:
src/problem1/index.tsThree distinct implementations of
sum_to_n(n), each returning1 + 2 + ... + n. Forn ≤ 0all three consistently return0(empty sum).forloopn*(n+1)/2Array.from+reduceImplementation B is the practical choice for any real usage. Implementation C demonstrates a functional style that composes naturally with further sequence transforms.
Problem 2: Fancy Form
Location:
src/problem2/— run withnpm install && npm run devA currency swap form built with Vite + React + TypeScript (bonus stack).
Key features:
receiveAmount = sendAmount × (fromPrice / toPrice).Unit tests for the pure
lib/logic (exchange-rate math, price deduplication/filtering) are insrc/lib/*.test.tsand run withnpm test.Problem 3: Messy React
Location:
src/problem3/README.mdlists 13 issues found in the originalWalletPagecomponent, ordered from most to least severe:lhsPriorityis not defined → runtimeReferenceError(should bebalancePriority)amount <= 0instead of> 0WalletBalanceinterface missing theblockchainfield used in the codegetPriorityre-created on every render (should be hoisted to module scope)blockchain: anyparameter discards type safetypricesinuseMemodeps but never used by the filter/sortundefinedfor equal prioritiesrowsmaps oversortedBalancesbut casts toFormattedWalletBalance→balance.formattedis alwaysundefinedformattedBalancesnot memoised — runs on every renderkeyprices[balance.currency]unguarded → potentialNaNtoFixed()called without a precision argumentchildrendestructured but never usedWalletPage.tsxis the refactored version: typedBlockchainunion,getPriorityhoisted with aneverexhaustiveness check, a singleuseMemothat filters, sorts, and formats in one pass, stable composite keys, and guardedusdValue.